package com.zijidelu.luframework.starter.beans;

import com.zijidelu.luframework.config.json.DefaultJacksonCustomizer;
import com.zijidelu.luframework.config.json.LuFrameworkJacksonCustomizer;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;

/**
 * Jackson自动配置
 */
@AutoConfiguration
public class JacksonAutoConfiguration {

    /**
     * 当没有其他LuFrameworkJacksonCustomizer Bean时，使用默认实现
     */
    @Bean
    @ConditionalOnMissingBean(LuFrameworkJacksonCustomizer.class)
    public LuFrameworkJacksonCustomizer luFrameWorkJacksonCustomizer() {
        return new DefaultJacksonCustomizer();
    }

    /**
     * 创建Jackson2ObjectMapperBuilderCustomizer Bean
     * 使用注入的LuFrameworkJacksonCustomizer来创建自定义器
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer(
            LuFrameworkJacksonCustomizer luFrameworkJacksonCustomizer) {
        return luFrameworkJacksonCustomizer.createJacksonCustomizer();
    }
}